import { getPageMetadataAndSlug } from '@mintlify/common';
import { getLocationErrString } from '../errorMessages/getLocationErrString.js';
import { preparseMdx } from './preparseMdx/index.js';
export const createPage = async (pagePath, pageContent, contentDirectoryPath, openApiFiles, suppressErrLog = false) => {
    let pageMetadata;
    let slug;
    try {
        const { pageMetadata: metadata, slug: pageSlug } = getPageMetadataAndSlug(pagePath, pageContent, openApiFiles);
        pageMetadata = metadata;
        slug = pageSlug;
        pageContent = await preparseMdx(pageContent, contentDirectoryPath, pagePath, suppressErrLog);
    }
    catch (err) {
        console.log(`\n ⚠️  Parsing error in the frontmatter: ${getLocationErrString(pagePath, contentDirectoryPath, err)}: `);
        // TODO - pages completely break in our backend when frontmatter is broken.
        // Unify "createPage" function across applications and properly catch errors
        throw err;
    }
    return {
        pageMetadata,
        pageContent,
        slug,
    };
};
